package com.desginer.struct.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class UserServiceProxy implements InvocationHandler {

    Object target;

    public UserServiceProxy(Object target){
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (!checkPermission()){
            // 没有权限
            throw new IllegalAccessException();
        }
        Object invoke = method.invoke(target, args);

        System.out.println("权限校验。。。");
        return invoke;
    }

    private boolean checkPermission() {
        /**
         * 校验代理方法
         */
        System.out.println("执行代理校验方法");
        return true;
    }


}
